package cn.tedu.lbs.basic.web.controller;

import cn.tedu.lbs.basic.web.service.BusinessService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.query.BusinessQuery;
import com.tarena.lbs.pojo.basic.vo.BusinessCategoryVO;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 和商家业务有关的功能模块
 */
@RestController
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    /**
     * 后台商家数据的分页列表查询
     */
    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> pageList(BusinessQuery businessQuey){
        //从业务层要 分页数据
        PageResult<BusinessVO> voPage=businessService.pageList(businessQuey);
        return new Result<>(voPage);
    }
    //一旦 行业分类非常多 1000个 添加搜索按钮
    @GetMapping("/admin/basic/business/category/list/")
    public Result<List<BusinessCategoryVO>> categoryList(){
        return new Result<>(businessService.categoryList());
    }
    //新增提交商家表单
    //入参格式 不再是表单格式 就是json
    @PostMapping("/admin/basic/business/info/save")
    public Result<Void> save(@RequestBody BusinessParam param)throws BusinessException {
        businessService.save(param);
        return Result.success();//code=0 message=ok
    }
}
